package cn.stimd.spring.aop.support.annotation;

import cn.stimd.spring.aop.ClassFilter;
import cn.stimd.spring.aop.MethodMatcher;
import cn.stimd.spring.aop.Pointcut;

import java.lang.annotation.Annotation;

/**
 * Created by Stimd
 * 项目地址：https://gitee.com/stimd/spring-wheel
 * 公众号：Java编程探微
 */
public class AnnotationMatchingPointcut implements Pointcut {
    private final ClassFilter classFilter;
    private final MethodMatcher methodMatcher;


    public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType,
                                      Class<? extends Annotation> methodAnnotationType) {

        if (classAnnotationType != null) {
            this.classFilter = new AnnotationClassFilter(classAnnotationType);
        } else {
            this.classFilter = ClassFilter.TRUE;
        }

        if (methodAnnotationType != null) {
            this.methodMatcher = new AnnotationMethodMatcher(methodAnnotationType);
        } else {
            this.methodMatcher = MethodMatcher.TRUE;
        }
    }

    @Override
    public ClassFilter getClassFilter() {
        return this.classFilter;
    }

    @Override
    public MethodMatcher getMethodMatcher() {
        return this.methodMatcher;
    }
}
